﻿// CCalib_IntrinInit_Dlg.cpp: 实现文件
//

#include "pch.h"
#include "SakerProject.h"
#include "Calib_IntrinInit_Dlg.h"
#include "afxdialogex.h"

#include "xxFileProcess.h"
#include "xxDataFormat.h"
#include "xxWidgetControl.h"

#include "mmProduct.h"
#include "mmFile_Paras.h"


// CCalib_IntrinInit_Dlg 对话框
CCalib_IntrinInit_Dlg * m_Calib_IntrinInit;

IMPLEMENT_DYNAMIC(CCalib_IntrinInit_Dlg, CDialogEx)

CCalib_IntrinInit_Dlg::CCalib_IntrinInit_Dlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_Calib_IntrinInit, pParent)
{

}

CCalib_IntrinInit_Dlg::~CCalib_IntrinInit_Dlg()
{
}

void CCalib_IntrinInit_Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CCalib_IntrinInit_Dlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_Load, &CCalib_IntrinInit_Dlg::OnBnClickedButtonLoad)
END_MESSAGE_MAP()


// CCalib_IntrinInit_Dlg 消息处理程序


void CCalib_IntrinInit_Dlg::OnBnClickedButtonLoad()
{
	if (mmCalib.IntrinInit != NULL) {
		delete mmCalib.IntrinInit;
	}
	mmCalib.IntrinInit = new uuIntrin;







	
	int PN = _ttoi(mmProduct.ProductNo);
	CString ProductNo;
	ProductNo.Format(L"01003487220525%04d", PN);
	//mmProduct.UpdateProductNo(ProductNo, TRUE);
	CString CsvPath = mmFile_Paras.ModelFolderPath() + L"CalibResult.csv";
	vector<CString> vecCStrs = xx::ReadFile(CsvPath);
	for (int i = 2; i < (int)vecCStrs.size(); i++) {
		CString CStrs = vecCStrs[i];
		vector<CString> vecContents = xx::ToVecCString(CStrs, L",");
		if (_ttoi(vecContents[0]) == PN) {
			mmCalib.IntrinInit->u0 = xx::WriteWidget(this, IDC_EDIT_u0, _ttof(vecContents[2]));
			mmCalib.IntrinInit->v0 = xx::WriteWidget(this, IDC_EDIT_v0, _ttof(vecContents[5]));
			mmCalib.IntrinInit->fx = xx::WriteWidget(this, IDC_EDIT_fx, _ttof(vecContents[8]));
			mmCalib.IntrinInit->fy = xx::WriteWidget(this, IDC_EDIT_fy, _ttof(vecContents[9]));
			mmCalib.IntrinInit->ReproErr = xx::WriteWidget(this, IDC_EDIT_ReproErr, _ttof(vecContents[11]));
			mmCalib.IntrinInit->k1 = xx::WriteWidget(this, IDC_EDIT_k1, _ttof(vecContents[12]));
			mmCalib.IntrinInit->k2 = xx::WriteWidget(this, IDC_EDIT_k2, _ttof(vecContents[13]));
			mmCalib.IntrinInit->p1 = xx::WriteWidget(this, IDC_EDIT_p1, _ttof(vecContents[14]));
			mmCalib.IntrinInit->p2 = xx::WriteWidget(this, IDC_EDIT_p2, _ttof(vecContents[15]));
			mmCalib.IntrinInit->k3 = xx::WriteWidget(this, IDC_EDIT_k3, _ttof(vecContents[16]));
			mmCalib.IntrinInit->k4 = xx::WriteWidget(this, IDC_EDIT_k4, _ttof(vecContents[17]));
			mmCalib.IntrinInit->k5 = xx::WriteWidget(this, IDC_EDIT_k5, _ttof(vecContents[18]));
			mmCalib.IntrinInit->k6 = xx::WriteWidget(this, IDC_EDIT_k6, _ttof(vecContents[19]));
			break;
		}
	}
	

	
	
}
